<?php
	$usr = new User_subscribe();
	if(isset($_POST['user_name'])){
		$usr_info = $usr->saveUserDetail();		
	}
?>	
<div class="span3 right_container">		
	
	<div class="right_blog_container">
		<div class="right_blog_header">
			<div><h3 class="uiHeaderTitle">Subscribe Now</h3></div>
		</div>
		<div class="right_blog_content">
			
			<?php 
				if(isset($usr_info) && trim($usr_info)!=''){										
			?>
			<div class="alert alert-error">
				<div style="float: right; width: 5%;"><button type="button" class="close" data-dismiss="alert">&times;</button></div>
				<div style="float:left;width: 92%;word-wrap: break-word;"><?php echo $usr_info; ?></div>
				<div style="clear:both;"></div>							
			</div>
			<?php
				}
			?>
			<!--<h4 class="title"><span class="text"><strong>SUBSCRIBE</strong> Form</span></h4>-->			
			<form action="<?php echo $_SERVER['PHP_SELF']; ?>?home=1" method="POST" name="email_subscribe" >
				<input type="hidden" name="next" value="/">
				<fieldset>
					<div class="control-group">
						<label class="control-label">Username</label>
						<div class="controls">
							<input type="text" placeholder="Username" name="user_name" id="user_name" class="input-xlarge subs_width" >
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">Email</label>
						<div class="controls">
							<input type="text" name="user_email" id="user_email"  placeholder="Email" class="input-xlarge subs_width">
						</div>
					</div>
					<div class="control-group">
						<button tabindex="3" type="button" class="btn btn-inverse large subscribe_button">Subscribe</button> 
					</div>
				</fieldset>
			</form>
		</div>
	</div>

	<div class="right_blog_container">
		<div class="right_blog_header">
			<div><h3 class="uiHeaderTitle">Latest News</h3></div>
		</div>
		<div class="right_blog_content" style="min-height:200px;">
			<marquee direction="up" loop="true" style="font-size: 15px;line-height: 25px;"><img src="img/vipin_s.jpg"><br><span style="color: red;"><?php
				$sel = "SELECT *FROM tbl_latest_news";
				$query = mysql_query($sel) or die(mysql_error());
				if(mysql_num_rows($query)>0){
					while($row = mysql_fetch_array($query)){
						echo $row['latest_news'];
					}
				}
			?></span></marquee>			
		</div>
	</div>

	<div id="fb-root"></div>
	<script type="text/javascript">
		 (function (d, s, id) {
			 var js, fjs = d.getElementsByTagName(s)[0];
			 if (d.getElementById(id)) return;
			 js = d.createElement(s); js.id = id;
			 js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
			 fjs.parentNode.insertBefore(js, fjs);
		 } (document, 'script', 'facebook-jssdk'));
	</script>
	<div class="fb_blog_container">
		<div class="fb-like-box" data-href="http://www.facebook.com/rvtrainingsolutions" data-width="200" data-height="300" data-show-faces="true" data-stream="false" data-border-color="black" data-header="true"></div>
	</div>	

</div>
<script>
	$ = jQuery.noConflict();
	$(document).ready(function(){	
		$('.subscribe_button').click(function(){
			
			if($('#user_name').val().trim() == ''){			
				alert("Please enter a value for the \"User Name\" field.");
				$('#user_name').focus();
				return (false);
			}			
			else if($('#user_email').val() == "")
			{
				alert("Please enter a value for the \"Email\" field.");
				$('#user_email').focus();				
				return (false);
			}
			else if(($('#user_email').val().indexOf("\@") == -1) || ($('#user_email').val().indexOf(".")== -1) || isInvalidateEmail($('#user_email').val()))
			{
				alert("Invalid Email Address");
				$('#user_email').focus();
				return (false);
			}
			else
			{
				document.email_subscribe.submit();
			}

		});
		
	});

	function isInvalidateEmail(str)
	{
		var atpos=str.indexOf("@");
		var dotpos=str.lastIndexOf(".");
		if (atpos<1 || dotpos<atpos+2 || dotpos+2>=str.length)
		  {
		  return true;
		  }
		return false;
	}

</script>